﻿// JScript File

function CheckAll(objName,checked)
{
    for (var i=0;i<document.forms[0].elements.length;i++)
    {
        var e = document.forms[0].elements[i];
        if (e.name == objName)
	        e.checked = checked;
    }
}

//  ---------------------------------------

function SelectedAll(objName)
{
    for (var i=0;i<document.forms[0].elements.length;i++)
    {
        var e = document.forms[0].elements[i];
        if (e.name == objName)
	        if(!e.checked)
	            return false;	      
    }
    
    return true;
}

//  ---------------------------------------

function Item_Select(obj, Lobj)
{
        var objTemp = document.getElementById(obj);        
        if(objTemp)
            objTemp.checked = SelectedAll(Lobj);
}

//  ---------------------------------------

function ConfirmOption(msgEmty, msgQuestion)
{
  if( ! Chk_BeforeDelete(msgEmty, 'iptSelect'))
  return false;
  return confirm(msgQuestion);
}

//  ---------------------------------------

function Chk_BeforeDelete(msgEmty, object)
{
  for (var i = 0; i < document.forms[0].elements.length; i ++ )
  {
    var e = document.forms[0].elements[i];
    if (e.name == object)
    if(e.checked)
    return true;
  }
  alert(msgEmty);
  return false;
}

 //<input id="selectall" name="selectall" title="Chọn để xóa" onclick="javascript:CheckAll('iptSelect', this.checked);"
  //                          type="checkbox" />
  
   //<input id="Checkbox1" name="iptSelect" title="Chọn" onclick="Item_Select('selectall', 'iptSelect');"
     //                       type="checkbox" value='<%#Eval("FormID")%>' />
     
//------------------------------------------

function PerformClick(e, target) 
{
    if (e.which || e.keyCode)
    {
        if ((e.which == 13) || (e.keyCode == 13))
        {
            document.getElementById(target).click();
            return false;
        }
    }
    else
    {
        return true;
    } 
}

//  ---------------------------------------

function ShowHiddenDiv(ctl)
{
    document.getElementById(ctl).style.display = document.getElementById(ctl).style.display == "none" ? "block" : "none";
}

//  ---------------------------------------

//Truyền vào tên control
function ShowHiddenControl(ctl)
{
    try
    {
        document.getElementById(ctl).style.display = document.getElementById(ctl).style.display == "none" ? "block" : "none";
    }
    catch(e){}
}

//  ---------------------------------------

//An hien 2 coltrol
function CalendarShow(isSelect,ctl1,ctl2)
{
    try
    {
        if(isSelect==1)
        {
            document.getElementById(ctl1).style.display = "none";
            document.getElementById(ctl2).style.display = "block";
        }   
        else
        {
            document.getElementById(ctl1).style.display = "block";
            document.getElementById(ctl2).style.display = "none";
        }
       
    }
    catch(e){  
    }
}

//-----------------------------------------
function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

// Thuc hien voi mot CheckBox cu the khi duoc dua ten
function BeforeAction(msgEmty, msgQuestion,objCheck)
{
  if(!BeforeDelete(msgEmty,objCheck))
  return false;
  return confirm(msgQuestion);
}


//Kiem tra xem co check nao duoc chon hay khong
function BeforeDelete(msgEmty,objCheck)
{
  for (var i = 0; i < document.forms[0].elements.length; i ++ )
  {
    var e = document.forms[0].elements[i];
    if (e.name == objCheck)
    if(e.checked)
    return true;
  }
  alert(msgEmty);
  return false;
}

function ClearText(ctr)
{
    document.getElementById(ctr).value='';        
}